#!/bin/sh

mkdir -p /data/wanli-pay/channel-server/`hostname`/
ln -s /data/wanli-pay/channel-server/`hostname`/ /data/logs

set -x
term_handler() {
  curl "localhost:22333/offline"
   sleep 20s
  echo '准备kill java进程'
  ps -ef | grep java | grep channel-server | cut -c 9-15 | xargs kill
}

trap 'term_handler' 15

exec java -Dfile.encoding=UTF-8 $JAVA_OPTS -javaagent:/usr/local/skywalking/agent/skywalking-agent.jar=$SW_PARAMS  -jar /usr/local/channel-server.jar &

while true
do
  sleep 5
  pidof java||exit 1
done